312B - Archer - CodeForces Solution


math probabilities *1300

Please click on ads to support us..

Python Code:

a,b,c,d=map(int,input().split())
start=(1-a/b)*(1-c/d)
current=start
result=start+1
while current > 0.000001 :
    current=current*start
    result+=current
print(result*a/b)

C++ Code:

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
#define ld long double
#define vll vector<int>
#define vpl vector<pair<int, int>>
#define pb push_back
#define all(n) n.begin(), n.end()
#define rev(n) reverse(n.begin(), n.end())
#define fr(n) for(int i=0; i<n; i++)
#define frl(k,n) for(int j=k; j<n; j++)
#define cinv(a,n) for(int j=0;j<n;j++) cin>>a[j]
#define yn(x) cout << ((x) ? "YES\n" : "NO\n")
#define endl '\n'
const int M = 1e9+7;

bool poweroftwo(int n) { return !(n & (n - 1)); }
int pow(int a, int b, int m=M) {int ans=1;while (b){if(b&1) ans=(ans*a)%m; a=(a*a)%m; b >>= 1;}return ans;}
// const int N = 4e4;
// bool seive[N]; vector<int> primes;
// void know_all_primes(){for(int i = 2; i < N; ++i){seive[i] = true;}for(int i = 2; i < N; ++i){if (seive[i]) {primes.push_back(i);for(int j = i *i; j < N; j += i){seive[j] = false;}}}}
vector<int> know_all_prime(int num) { vector<int> ans; for(int i=2; i*i<=num; i++) { if(num%i==0) { ans.push_back(i);} while (num % i == 0) { num /= i;}} if (num > 1){ ans.push_back(num); } return ans; }

mt19937 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());

void testCase(){
    // int n = 0, m = 0, c = 1, k = -1, sum = 0; string s; bool f = true;
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    double cr = (1-a/b)*(1-c/d);
    cr = 1.0 - cr;
    a = a/b;
    cout << fixed << setprecision(6) << a/cr << endl;
}   

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int test = 1;
    // cin >> test;
    while(test--)  {testCase();}
    return 0;
}


Comments

Submit
0 Comments
More Questions

1038B - Non-Coprime Partition
43A - Football
50A - Domino piling
479A - Expression
1480A - Yet Another String Game
1216C - White Sheet
1648A - Weird Sum
427A - Police Recruits
535A - Tavas and Nafas
581A - Vasya the Hipster
1537B - Bad Boy
1406B - Maximum Product
507B - Amr and Pins
379A - New Year Candles
1154A - Restoring Three Numbers
750A - New Year and Hurry
705A - Hulk
492B - Vanya and Lanterns
1374C - Move Brackets
1476A - K-divisible Sum
1333A - Little Artem
432D - Prefixes and Suffixes
486A - Calculating Function
1373B - 01 Game
1187A - Stickers and Toys
313B - Ilya and Queries
579A - Raising Bacteria
723A - The New Year Meeting Friends
302A - Eugeny and Array
1638B - Odd Swap Sort